import { _decorator, Node, Sprite, tween, Vec3, Color } from 'cc';
import { BaseEffect } from './BaseEffect';

const { ccclass, property } = _decorator;

@ccclass('RoarEffect')
export class RoarEffect extends BaseEffect {
    @property(Node)
    private waveNode: Node | null = null;

    @property(Sprite)
    private waveSprite: Sprite | null = null;

    @property
    private maxRadius: number = 5;

    @property
    private expandDuration: number = 0.5;

    private waveTween: any = null;

    start() {
        super.start();
        if (this.waveNode) {
            this.waveNode.scale = Vec3.ZERO;
            if (this.waveSprite) {
                this.waveSprite.color = new Color(255, 255, 255, 255);
            }
        }
    }

    protected onEffectStart(): void {
        if (!this.waveNode) return;

        // 重置波纹状态
        this.waveNode.scale = Vec3.ZERO;
        if (this.waveSprite) {
            this.waveSprite.color = new Color(255, 255, 255, 255);
        }

        // 创建波纹扩散动画
        this.waveTween = tween(this.waveNode)
            .parallel(
                tween().to(this.expandDuration, { scale: new Vec3(this.maxRadius, this.maxRadius, 1) }),
                tween(this.waveSprite)
                    .to(this.expandDuration, { color: new Color(255, 255, 255, 0) })
            )
            .start();
    }

    protected onEffectEnd(): void {
        if (this.waveTween) {
            this.waveTween.stop();
        }
    }
} 